<%@ page import="com.scalar.forecast.forecastEntry.RowData,
				 com.scalar.forecast.commons.Constants,
				 com.scalar.chiptrack.utils.ConfigManager"%>
 <%--
  User: Sujan
  Date: Jun 2, 2005
  Time: 2:26:47 PM
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="/WEB-INF/struts-html.tld"  prefix="html"%>
<%@ taglib uri="/WEB-INF/struts-nested.tld"  prefix="nested"%>
<%String chipTracContext = "/" + ConfigManager.getChipTracContext();%>
<% String rowIds[] = null; int rootCnt = 0, rowCnt = 0; %>
<nested:root  name="forecastEntryForm" >
<nested:iterate property="tableDataList" indexId="tableDataListIdx" id="rowData" >
<%
	rowCnt++;
	int maxLevel = ( ( RowData )rowData ).getMaxLevelOrder();
	int currentLevel = ( ( RowData ) rowData ).getLevelOrder();

	//if ( tableDataListIdx.intValue() == 0 )
	if ( maxLevel == currentLevel )
	{
		rootCnt++;
		rowIds = new String[ maxLevel + 1 ];
		for ( int i=0; i < maxLevel+1; i++ )
		{
			rowIds[i] = new String("");
		}
	}

	StringBuffer rowId = new StringBuffer ( "" );
	if ( "".equals( rowIds[ currentLevel ] ) )
	{
		if ( currentLevel == maxLevel )
		{
			rowId.append ( "r" );     //
			rowId.append ( rootCnt );   //
			rowId.append ( "l" );
			rowId.append ( maxLevel );
		}
		else if ( currentLevel < maxLevel )
		{
			rowId.append ( rowIds[ currentLevel + 1 ] );
			rowId.append ( "c1" );
		}
		/*for ( int i=0; i < ( maxLevel - currentLevel ); i++ )
		{
			rowId.append( "c1" );
		}*/
		rowIds[currentLevel] = rowId.toString();
	}
	else
	{
		rowId.append ( rowIds[ currentLevel ] );
		int childCnt = Integer.parseInt ( rowId.substring( rowId.lastIndexOf( "c" )+1 ) );
		childCnt = childCnt + 1;
		rowId.replace( rowId.lastIndexOf ( "c" )+1,rowId.length(),Integer.toString( childCnt ) );
		rowIds[ currentLevel ] = rowId.toString();
		for ( int i=currentLevel-1; i >= 0 ; i-- )
		{
			rowIds[ i ] = "";
		}
	}
	int colorIdx = ( maxLevel - currentLevel ) + 1;
	int noOfSpaces = maxLevel - currentLevel;
	String styleDisplay = ( maxLevel == currentLevel ) ? "block" : "none";
%>
  <TR align="right" class='color<%=( colorIdx > 4 ) ? 4 : colorIdx %>' id='<%=rowId.toString()%>' style="DISPLAY: <%=styleDisplay%>"><!-- level-4 row  ( root )-->
	<nested:notEqual property="maxLevelOrder" value="1">
	<TD>
	   <TABLE align="left">
		 <TBODY >
		 <TR>
			<%
				for ( int i=0; i < noOfSpaces; i++ )
				{
			%>
					<TD><IMG src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=10></TD>
			<%
				}
				if ( currentLevel != 1 && ( ( RowData ) rowData ).isHasChilds() )
				{

			%>
				   <TD><IMG id='<%=rowId.toString()%>img' onclick=toggle(<%=rowId.toString()%>,this)
					 src="<%=chipTracContext%>/jsp/includes/images/plus.gif"  width=10></TD>
			 <%
				}
				else
				{
			%>
				   <TD><IMG src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=10></TD>
			<%
				}
				if ( currentLevel == maxLevel || ( currentLevel+1 ) == maxLevel )
				{
					String onClickEvent = "toggleEnableDisable(this," + tableDataListIdx.intValue() + ")";
			 %>
					<TD>
							<nested:checkbox property="selected" onclick="<%=onClickEvent%>" />
					</TD>
			<%
				}
				else
				{
			%>
					<nested:hidden property="selected"/>
			<%
				}
			%>
					<TD class=NArialL>
						<nested:hidden property="salesPersonName"/>
						<nested:write property="salesPersonName"/>
					</TD></TR>
			</TBODY>
		</TABLE>
	</TD>
	 </nested:notEqual>
	 <nested:equal property="maxLevelOrder" value="1">
		<nested:hidden property="salesPersonName"/>
		<nested:hidden property="selected"/>
		<TD></TD>
	 </nested:equal>
		   <% String rowDataProp = "",slotDataProp="",actualRowDataProp="", rowDataDefaultValuesProp="" ; %>
		   <nested:iterate property="slotDataList" indexId="slotDataListIdx" id="slotData">
				<nested:nest property="/tableMetaData">
					<nested:iterate property="tableColumnList">
					 <nested:equal property="display" value="true">
						 <%  rowDataProp = "/tableDataList[" + tableDataListIdx.intValue()+ "]";
							 actualRowDataProp = "/actualTableDataList[" + tableDataListIdx.intValue()+ "]";
							 slotDataProp = "slotDataList[" + slotDataListIdx.intValue() + "]";
							 rowDataDefaultValuesProp = "/tableDataListDefaultValues[" + tableDataListIdx.intValue()+ "]";
							 boolean disabled = true;
						  %>
						<nested:equal property="name" value="Qty">
						  <nested:nest property="<%=rowDataProp%>">
								<nested:nest property="<%= slotDataProp%>">
							<TD class=NArialL valign="top" nowrap>
									<nested:hidden property="rowId"/>
							  <%
								  disabled = true;
								if ( currentLevel == maxLevel || ( currentLevel+1 ) == maxLevel )
								{
							  %>   <nested:nest property="<%=rowDataProp%>" >
										<nested:equal property="selected" value="true">
											<% disabled = false; %>
										</nested:equal>
										<nested:nest property="<%=slotDataProp%>">
											<nested:text property="qty" size="7" styleClass="valuetxfield" disabled="<%=disabled%>" onkeypress="javascript:allowInteger()" maxlength="6"/>
										</nested:nest>
								   </nested:nest>

								   <nested:nest property="<%=rowDataDefaultValuesProp%>" >
										<nested:nest property="<%=slotDataProp%>">
											<nested:hidden property="qty" />
										</nested:nest>
								   </nested:nest>
							  <%
								}
								else
								{
							  %>
									<nested:write property="qty"/>
							  <%
								}
							  %>
									<nested:nest property="<%=actualRowDataProp%>" >
										<nested:equal property="showActualData" value="true">
											<nested:nest property="<%=slotDataProp%>">
												<BR><FONT COLOR="RED"><nested:write property="qty"/></FONT>
											</nested:nest>
										</nested:equal>
									</nested:nest>
							</TD>
						   </nested:nest>
						  </nested:nest>

						</nested:equal>
						<nested:equal property="name" value="Price">
							<nested:nest property="<%=rowDataProp%>">
								<nested:nest property="<%=slotDataProp%>">
							<TD class=NArialL valign="top" nowrap>
								<%
									disabled=true;
									if ( currentLevel == maxLevel || ( currentLevel+1 ) == maxLevel )
									{
								%>
									<nested:nest property="<%=rowDataProp%>" >
									  <nested:equal property="selected" value="true">
										<% disabled = false; %>
									  </nested:equal>
										<nested:nest property="<%=slotDataProp%>">
											<nested:text property="price" size="8"  maxlength="7" styleClass="valuetxfield" disabled="<%=disabled%>" onkeyup="javascript:restrictAmt(this,4,2)" onkeydown="storePrevValue(this)" onkeypress="javascript:restrictCharacters(this,4,2)"/>
										</nested:nest>
								   </nested:nest>

								   <nested:nest property="<%=rowDataDefaultValuesProp%>" >
										<nested:nest property="<%=slotDataProp%>">
											<nested:hidden property="price" />
										</nested:nest>
								   </nested:nest>
								<%
									}
									else
									{
								%>
										<nested:write property="price"/>
								<%
									}
								%>
										<nested:nest property="<%=actualRowDataProp%>" >
											<nested:equal property="showActualData" value="true">
												<nested:nest property="<%=slotDataProp%>">
													<BR><FONT COLOR="RED"><nested:write property="price"/></FONT>
												</nested:nest>
											</nested:equal>
										</nested:nest>
							</TD>
								</nested:nest>
							</nested:nest>
						</nested:equal>
						<nested:equal property="name" value="Confidence Level">
							<nested:nest property="<%=rowDataProp%>">
								<nested:nest property="<%=slotDataProp%>">
							<TD class=NArialL valign="top" nowrap>
								<%
									disabled = true;
									if ( currentLevel == 1 )
									{
										if ( currentLevel == maxLevel || ( currentLevel+1 ) == maxLevel )
										{
								%>
											<nested:nest property="<%=rowDataProp%>" >
											  <nested:equal property="maxLevelOrder" value="1">
												<% disabled = false; %>
											  </nested:equal>
												<nested:nest property="<%=slotDataProp%>">
													<nested:text property="confidenceLevel" size="6" styleClass="valuetxfield" disabled="<%=disabled%>" maxlength="6" onkeyup="javascript:restrictAmt(this,3,2)" onkeydown="storePrevValue(this)" onkeypress="javascript:restrictCharacters(this,3,2)"/>
												</nested:nest>
										   </nested:nest>

										   <nested:nest property="<%=rowDataDefaultValuesProp%>" >
												<nested:nest property="<%=slotDataProp%>">
													<nested:hidden property="confidenceLevel" />
												</nested:nest>
								   			</nested:nest>
								<%
										}
										else
										{
								%>
											<nested:write property="confidenceLevel"/>
								<%
										}
								%>
										<nested:nest property="<%=actualRowDataProp%>" >
											<nested:equal property="showActualData" value="true">
												<nested:nest property="<%=slotDataProp%>">
													<BR><FONT COLOR="RED"><nested:write property="confidenceLevel"/></FONT>
												</nested:nest>
											</nested:equal>
										</nested:nest>
								<%
									}
								%>
							</TD>
							</nested:nest>
								</nested:nest>
						</nested:equal>
						<nested:equal property="name" value="<%=Constants.COLUMN_USERLIST1%>">
							<nested:nest property="<%=rowDataProp%>">
								<nested:nest property="<%=slotDataProp%>">
							<TD class=NArialL valign="top" nowrap>
								<%
									disabled = true;
									if ( currentLevel == maxLevel || ( currentLevel+1 ) == maxLevel )
									{
								%>
										<nested:nest property="<%=rowDataProp%>" >
											<nested:equal property="selected" value="true">
												<% disabled = false; %>
											</nested:equal>
											<nested:nest property="<%=slotDataProp%>">
												<nested:select property="userList1" styleClass="txfield" disabled="<%=disabled%>">
													<html:options collection="<%=Constants.COLUMN_USERLIST1%>" labelProperty="label" property="value"/>
												</nested:select>
											</nested:nest>
										</nested:nest>

										<nested:nest property="<%=rowDataDefaultValuesProp%>" >
											<nested:nest property="<%=slotDataProp%>">
												<nested:hidden property="userList1" />
											</nested:nest>
								   		</nested:nest>
								<%
									}
									else
									{
								%>
										<nested:write property="userList1"/>
								<%
									}
								%>
										<nested:nest property="<%=actualRowDataProp%>" >
											<nested:equal property="showActualData" value="true">
												<nested:nest property="<%=slotDataProp%>">
													<BR><FONT COLOR="RED"><nested:write property="userList1"/></FONT>
												</nested:nest>
											</nested:equal>
										</nested:nest>
							</TD>
							 </nested:nest>
								</nested:nest>
						</nested:equal>
						<nested:equal property="name" value="<%=Constants.COLUMN_USERDATE1%>">
							<nested:nest property="<%=rowDataProp%>">
								<nested:nest property="<%=slotDataProp%>">
							<TD class=NArialL valign="top" nowrap>
								<%
									disabled = true;
									if ( currentLevel == maxLevel || ( currentLevel+1 ) == maxLevel )
									{
								%>
										<nested:nest property="<%=rowDataProp%>" >
										  <nested:equal property="selected" value="true">
											<% disabled = false; %>
										  </nested:equal>
											<nested:nest property="<%=slotDataProp%>">
												<nested:text property="userDate1" size="12" styleClass="valuetxfield" disabled="<%=disabled%>" maxlength="10"/>&nbsp;<a href="javascript:openCalendar(document.forecastEntryForm['tableDataList[<%=tableDataListIdx%>].slotDataList[<%=slotDataListIdx%>].userDate1'],<%=tableDataListIdx%>)"><img onMouseOver="window.status='Click here to select date';return true" border="0" align='center' src="<%=chipTracContext%>/jsp/includes/images/date_selector.gif" height=20 width=20></a>
											</nested:nest>
									   </nested:nest>

									   <nested:nest property="<%=rowDataDefaultValuesProp%>" >
											<nested:nest property="<%=slotDataProp%>">
												<nested:hidden property="userDate1" />
											</nested:nest>
									   </nested:nest>
								<%
									}
									else
									{
								%>
										<nested:write property="userDate1"/>
								<%
									}
								%>
										<nested:nest property="<%=actualRowDataProp%>" >
											<nested:equal property="showActualData" value="true">
												<nested:nest property="<%=slotDataProp%>">
													<BR><FONT COLOR="RED"><nested:write property="userDate1"/></FONT>
												</nested:nest>
											</nested:equal>
										</nested:nest>
							</TD>
								</nested:nest>
							</nested:nest>
						</nested:equal>
						<nested:equal property="name" value="<%=Constants.COLUMN_USERTXT1%>">
							<nested:nest property="<%=rowDataProp%>">
								<nested:nest property="<%=slotDataProp%>">
							<TD class=NArialL valign="top" nowrap>
								<%
									disabled = true;
									if ( currentLevel == maxLevel || ( currentLevel+1 ) == maxLevel )
									{
								%>
										<nested:nest property="<%=rowDataProp%>" >
										  <nested:equal property="selected" value="true">
											<% disabled = false; %>
										  </nested:equal>
											<nested:nest property="<%=slotDataProp%>">
												<nested:text property="userTxt1" size="10" styleClass="txfield" disabled="<%=disabled%>" maxlength="100"/>
											</nested:nest>
									   </nested:nest>

									   <nested:nest property="<%=rowDataDefaultValuesProp%>" >
											<nested:nest property="<%=slotDataProp%>">
												<nested:hidden property="userTxt1" />
											</nested:nest>
									   </nested:nest>
								<%
									}
									else
									{
								%>
										<nested:write property="userTxt1"/>
								<%
									}
								%>
										<nested:nest property="<%=actualRowDataProp%>" >
											<nested:equal property="showActualData" value="true">
												<nested:nest property="<%=slotDataProp%>">
													<BR><FONT COLOR="RED"><nested:write property="userTxt1"/></FONT>
												</nested:nest>
											</nested:equal>
										</nested:nest>
							</TD>
								</nested:nest>
							</nested:nest>
						</nested:equal>
						<nested:equal property="name" value="<%=Constants.COLUMN_USERTXT2%>">
							<nested:nest property="<%=rowDataProp%>">
								<nested:nest property="<%=slotDataProp%>">
							<TD class=NArialL valign="top" nowrap>
								<%
									disabled = true;
									if ( currentLevel == maxLevel || ( currentLevel+1 ) == maxLevel )
									{
								%>
										<nested:nest property="<%=rowDataProp%>" >
										  <nested:equal property="selected" value="true">
											<% disabled = false; %>
										  </nested:equal>
											<nested:nest property="<%=slotDataProp%>">
												<nested:text property="userTxt2" size="10" styleClass="txfield" disabled="<%=disabled%>" maxlength="100"/>
											</nested:nest>
									   </nested:nest>

									   <nested:nest property="<%=rowDataDefaultValuesProp%>" >
											<nested:nest property="<%=slotDataProp%>">
												<nested:hidden property="userTxt2" />
											</nested:nest>
									   </nested:nest>
								<%
									}
									else
									{
								%>
										<nested:write property="userTxt2"/>
								<%
									}
								%>
										<nested:nest property="<%=actualRowDataProp%>" >
											<nested:equal property="showActualData" value="true">
												<nested:nest property="<%=slotDataProp%>">
													<BR><FONT COLOR="RED"><nested:write property="userTxt2"/></FONT>
												</nested:nest>
											</nested:equal>
										</nested:nest>
							</TD>
								</nested:nest>
							</nested:nest>
						</nested:equal>
					 </nested:equal>
					</nested:iterate>
				</nested:nest>
		   </nested:iterate>
 </TR>
 </nested:iterate>
 <script>noOfRows=<%=rowCnt%>;</script>
</nested:root>